package org.beholder;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;

/**
 * Created by IntelliJ IDEA.
 * User: ddreval
 * Date: 02.10.12
 * Time: 17:36
 * To change this template use File | Settings | File Templates.
 */
public class ViewerServlet extends AbstractServlet {

	private static final long serialVersionUID = 1L;
	private Logger logger = Logger.getLogger(ViewerServlet.class);

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        int offset = 0;
        if (req.getParameter("offset")!=null) {
            try {
                offset = Integer.parseInt(req.getParameter("offset"));
            } catch (Exception e) {
                logger.error(e, e);
            }
        }
        List<Shot> list = getShots(offset);
        req.setAttribute("offset", new Integer(offset));
        req.setAttribute("list", list);
        req.getRequestDispatcher("/list.jsp").forward(req,resp);
        closeResources();
    }

}
